package com.seeTools.boot.pc.service.sys.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seeTools.boot.api.entity.sys.SysNotice;
import com.seeTools.boot.common.core.PageQuery;
import com.seeTools.boot.pc.mapper.sys.SysNoticeMapper;
import com.seeTools.boot.pc.service.BaseServiceImpl;
import com.seeTools.boot.pc.service.sys.SysNoticeService;
import com.seeTools.boot.pc.util.PageQueryHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author seeTools
 * @since 2024-06-08
 */
@Service
public class SysNoticeServiceImpl extends BaseServiceImpl<SysNoticeMapper, SysNotice> implements SysNoticeService {

    protected Logger logger = LoggerFactory.getLogger(getClass());


    @Resource
    private PageQueryHelper<SysNotice> pageQueryHelper;

    /**
     * 分页查询
     *
     * @param pageQuery 分页数据
     * @return 对象
     */
    @Override
    public Page<SysNotice> findList(PageQuery<SysNotice> pageQuery) {
        QueryWrapper<SysNotice> queryWrapper = getQueryWrapper(pageQuery.getDataObj());
        return dictionary(pageQueryHelper.pageInfo(this, pageQuery, queryWrapper));
    }

    /**
     * 查询数据
     *
     * @param model
     * @return
     */
    @Override
    public List<SysNotice> selectDataList(SysNotice model) {
        QueryWrapper<SysNotice> queryWrapper = getQueryWrapper(model);
        return dictionary(list(queryWrapper));
    }

    /**
     * 获取查询条件
     *
     * @param model
     * @return
     */
    public QueryWrapper<SysNotice> getQueryWrapper(SysNotice model) {
        QueryWrapper<SysNotice> queryWrapper = new QueryWrapper<>();
        LambdaQueryWrapper<SysNotice> lambdaQueryWrapper = queryWrapper.lambda();
        if (ObjectUtil.isNotEmpty(model)) {
            // 标题
            if (StrUtil.isNotEmpty(model.getTitle())) {
                lambdaQueryWrapper.eq(SysNotice::getTitle, model.getTitle());
            }
            // 类型
            if (StrUtil.isNotEmpty(model.getType())) {
                lambdaQueryWrapper.eq(SysNotice::getType, model.getType());
            }
        }
        return queryWrapper;
    }


    /**
     * 翻译数据
     *
     * @param page
     * @return
     */
    public Page<SysNotice> dictionary(Page<SysNotice> page) {
        if (ObjectUtil.isNotEmpty(page)) {
            List<SysNotice> list = page.getRecords();
            dictionary(list);
        }
        return page;
    }

    /**
     * 翻译
     *
     * @param list
     * @return
     */
    public List<SysNotice> dictionary(List<SysNotice> list) {
        if (CollUtil.isNotEmpty(list)) {
            list.forEach(item -> {
            });
        }
        return list;
    }
}


